<?php
include("include/haut.php");

$prof = getInfos($_GET['id']);

if(isset($_POST['mail']) && isset($_POST['fb']) && isset($_POST['ville']) && isset($_POST['phone'])){
	$mail = htmlentities($_POST['mail']);
	$fb = htmlentities($_POST['fb']);
	$ville = htmlentities($_POST['ville']);
	$phone = $_POST['phone'];
	$phone = (int) $phone;
	$phone = htmlentities($phone);
	if(isset($_POST['masq'])){
		$masq = "on";
	}
	else{
		$masq = "off";
	}

	$id = $prof['id'];
	majProfil($mail, $fb, $ville, $phone, $masq, $id);
	if(isset($_POST['statut'])){
		majStatut($_POST['statut'], $id);
	}
	if(!empty($_POST['mdp_actu']) AND !empty($_POST['mdp1']) AND !empty($_POST['mdp2'])){
		if(md5($_POST['mdp1']) == md5($_POST['mdp2']) AND md5($_POST['mdp_actu']) == $prof['password']){
			$newmdp = md5($_POST['mdp1']);
			majMdp($newmdp, $id);
		}
		else
		{
			header('Location: modif_profil.php?id='.$prof['id'].'&err=1');
			exit();
		}
	}
	header('Location: profil.php?id='.$prof['id']);
	exit();
}
if(estAdmin($user) and isset($_GET['action'])){
	if($_GET['action'] == "delete"){
	suprProfil($prof['id']);
	header("Location: liste_membre.php");
	exit();
}
}
if(!isConnected() OR !isset($_GET['id']) OR !idExiste(htmlentities($_GET['id'])) OR $_GET['id'] != $_SESSION['id']){
	if(!estAdmin($user)){
	header("Location: index.php");
	exit();
}
}

?>
<div id="corps">
	<h1>Modification</h1>
	<div id="centre">
		<?php if(isset($_GET['err'])){
			if($_GET['err'] == 1){?>
				<div id="msg_erreur">
				<p><b>Erreur:</b><br />
					Merci de verifier le mot de passe</p>
			</div><?php
			}
		}?>
		<form action="modif_profil.php?id=<?php echo $prof['id'];?>" method="POST">
			<label for="mail">Email :</label><br/>
			<input type="text" name="mail" id="mail" value="<?php echo $prof['email']; ?>"/></br>

			<label for="mdp_actu">Mot de passe actuel :</label><br/>
			<input type="password" name="mdp_actu" id="mdp_actu"> </input></br>

			<label for="mdp1">Nouveau mot de passe : </label><br/>
			<input type="password" name="mdp1" id="mdp1"> </input></br>

			<label for="mdp2">Confirmer mot de passe :</label><br/>
			<input type="password" name="mdp2" id="mdp2"> </input></br>

			<label for="fb">Facebook :</label><br/>
			<input type="text" name="fb" id="fb" value="<?php echo $prof['facebook']; ?>"/></br>

			<label for="ville">Ville : </label><br/>
			<input type="text" name="ville" id="ville" value="<?php echo $prof['ville']; ?>"/> </br>

			<label for="phone">Telephone : </label><br/>
			<input type="number" name="phone" id="phone" value="<?php echo $prof['num']; ?>"/> </br>

			<label for="masq">Protection des données :</label><br/>
			
			<?php 
			
			if($prof['privacy_np']){?>
			<input type="checkbox" name="masq" id="masq" checked /> Masquer les informations personelles</br>
			<?php
			}else
			{?>
			<input type="checkbox" name="masq" id="masq" value="off"/> Masquer les informations personelles</br>
			<?php
		}
		if(estAdmin($user)){?>
			<label for="statut">
				<select name="statut" id="statut">
					<?php
					if($prof['statut'] == "Admin"){?>
					    <option value="Admin" selected>Admin</option><?php
					}
					else{?>
					<option value="Admin">Admin</option><?php
				}
				    if($prof['statut'] == "President"){?>
					   <option value="President"   selected>Président</option><?php
					}
					else{?>
					<option value="President">Président</option><?php
				}
				    if($prof['statut'] == "Tresorier"){?>
					   <option value="Tresorier"  selected>Tresorier</option><?php
					}
					else{?>
					<option value="Tresorier">Tresorier</option><?php
				}
					if($prof['statut'] == "VP"){?>
					   <option value="VP"  selected>Vice-Président</option><?php
					}
					else{?>
					 <option value="VP">Vice-Président</option><?php
				}
				  
				if($prof['statut'] == "Membre"){?>
					   <option value="Membre" selected>Membre</option><?php
				}
				else{?>
					 <option value="Membre">Membre</option><?php
				}?>
				</select>
			</br>
				<?php
			}?>
<br/>
			<input type="submit"/></br>
		</form>

</div>
<?php
include("include/bas.php");
?>